﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CarInfor.DAL;

namespace CarInfor.UI
{
    public partial class frmMsgTemplate : Form
    {
        public frmMsgTemplate()
        {
            InitializeComponent();
            Bind();
        }

        private void Bind()
        {
            this.listView1.Items.Clear();
            MsgTemplate mt = new MsgTemplate();
            DataTable dt = mt.Query();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                ListViewItem li = new ListViewItem();
                li.Tag = dt.Rows[i]["编号"].ToString();
                li.SubItems[0].Text = (i + 1).ToString();
                li.SubItems.Add(dt.Rows[i]["短信内容"].ToString());
                this.listView1.Items.Add(li);
            }
        }

        private void btnClance_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// 获取选择的项
        /// </summary>
        /// <returns></returns>
        public string GetSelect()
        {
            if (this.listView1.SelectedItems.Count != 0)
            {
                return this.listView1.SelectedItems[0].SubItems[1].Text;
            }
            return string.Empty;

        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count != 0)
            {
                string id = this.listView1.SelectedItems[0].Tag.ToString();
                MsgTemplate mt = new MsgTemplate();
                mt.Delete(id);
                Bind();
            }
            else
            {
                MessageHelper.ShowInfo("请选择要删除的短信模板！");
            }
        }

        /// <summary>
        /// 导入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count != 0)
            {
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageHelper.ShowInfo("请选择要导入的短信模板！");
            }
        }
    }
}
